#!/usr/bin/env python
# coding=utf8

import requests
import json

headers = {'content-type': 'application/json'}

config_data = open('config.json')
config = json.load(config_data)
config_data.close()
## -----------------------------------------------------------------------
## function about bts rpc
## -----------------------------------------------------------------------
auth = (config["bts_rpc"]["username"], config["bts_rpc"]["password"])
url = config["bts_rpc"]["url"]
wallet_name = config["wallet_name"]
wallet_pass = config["wallet_pass"]

def wallet_create():
  request = {
              "method": "wallet_create",
              "params": [wallet_name,wallet_pass],
              "jsonrpc": "2.0",
              "id": 1
            }
  responce = requests.post(url, data=json.dumps(request), headers=headers, auth=auth)
  print("create wallet " + wallet_name + " :ok")

def wallet_open():
  request = {
              "method": "wallet_open",
              "params": [wallet_name],
              "jsonrpc": "2.0",
              "id": 1
            }
  responce = requests.post(url, data=json.dumps(request), headers=headers, auth=auth)
  print("open wallet " + wallet_name + " :ok")

def wallet_unlock():
  request = {
              "method": "wallet_unlock",
              "params": ["1772",wallet_pass],
              "jsonrpc": "2.0",
              "id": 1
            }
  responce = requests.post(url, data=json.dumps(request), headers=headers, auth=auth)
  print("unlock wallet " + wallet_name + " :ok")
  
def wallet_account_balance():
  request = {
              "method": "wallet_account_balance",
              "params": [],
              "jsonrpc": "2.0",
              "id": 1
            }
  responce = requests.post(url, data=json.dumps(request), headers=headers, auth=auth)
  balance = json.loads(vars(responce)["_content"])["result"]
  print(balance)
  
if __name__ == "__main__":
#  print (__name__)
#  wallet_create()
#  wallet_open()
  wallet_unlock()
  #wallet_account_balance()

